package tunnel

import (
	"fmt"
	"log"

	"internal-net-bridge-server/internal/tunnel/core"
	httpProto "internal-net-bridge-server/internal/tunnel/protocols/http"
	tcpProto "internal-net-bridge-server/internal/tunnel/protocols/tcp"
)

// ========================================
// 转发器工厂 - 创建协议转发器
// ========================================

// ForwarderFactory 转发器工厂
type ForwarderFactory struct {
	quicServer *QUICTunnelServer
}

// NewForwarderFactory 创建转发器工厂
func NewForwarderFactory(quicServer *QUICTunnelServer) *ForwarderFactory {
	return &ForwarderFactory{
		quicServer: quicServer,
	}
}

// CreateHTTPForwarder 创建HTTP转发器
func (f *ForwarderFactory) CreateHTTPForwarder() core.QUICForwarder {
	log.Printf("🔧 [转发器工厂] 创建HTTP转发器")
	return httpProto.NewForwarder(f.quicServer)
}

// CreateTCPForwarder 创建TCP转发器
func (f *ForwarderFactory) CreateTCPForwarder() core.QUICForwarder {
	log.Printf("🔧 [转发器工厂] 创建TCP转发器")
	return tcpProto.NewForwarder(f.quicServer)
}

// CreateForwarder 根据协议类型创建转发器
func (f *ForwarderFactory) CreateForwarder(protocolType core.ProtocolType) (core.QUICForwarder, error) {
	switch protocolType {
	case core.ProtocolHTTP:
		return f.CreateHTTPForwarder(), nil
	case core.ProtocolTCP:
		return f.CreateTCPForwarder(), nil
	default:
		return nil, fmt.Errorf("不支持的协议类型: %s", protocolType)
	}
}
